home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / pbwiz11.zip / PBWIZ.DOC < prev    next >
Text File  |  1992-01-11  |  53KB  |  1,390 lines

  1.                 The PowerBASIC Wizard's Library
  2.                 =-----------------------------=
  3.                           Version 1.1
  4.  
  5.      PBWIZ  Copyright (c) 1991-1992  Thomas G. Hanlin III
  6.  
  7.  
  8.  
  9. This is PBWiz, a library of assembly language and BASIC
  10. routines for use with PowerBASIC version 2.0.  Full source code
  11. is available with registration. The PBWiz collection is
  12. copyrighted and may be distributed only under the following
  13. conditions:
  14.  
  15. 1) No fee of over $10.00 may be charged for distribution. This
  16.    restriction applies only to physical copies and is not
  17.    meant to prevent distribution by telecommunication services.
  18.  
  19. 2) All PBWiz files must be distributed together in original,
  20.    unaltered form.  A list of the 11 files included may be
  21.    found in FILES.LST.
  22.  
  23. 3) No files may be added to the PBWiz collection.  This applies
  24.    most specifically to the practice of adding files with BBS
  25.    ads to archives, which I find seriously offensive.
  26.  
  27. You use this library at your own risk.  It has been tested by
  28. me on my own computer, but I will not assume any responsibility
  29. for any problems which PBWiz may cause you.  If you do
  30. encounter a problem, please let me know about it, and I will do
  31. my best to verify and repair the error.
  32.  
  33. It is expected that if you find PBWiz useful, you will register
  34. your copy. You may not use PBWiz routines in programs intended
  35. for sale unless you have registered.  Registration entitles you
  36. to receive the latest version of PBWiz, complete with full
  37. source code in assembly language and BASIC.  The assembly code
  38. is designed for the MASM 6.0 assembler and may require minor
  39. modifications if you wish to use it with OPTASM, TASM, or
  40. earlier versions of MASM.
  41.  
  42. Warning: Use of PBWiz for more than 30 days without registering
  43. may encourage the author to play bass drums under your window,
  44. so if you hear unexpected thunder, perhaps you've merely
  45. forgotten to send in your registration.  Beware!
  46.  
  47.                        Table of Contents                 page 2
  48.  
  49.  
  50.  
  51.  Overview and Legal Info .................................... 1
  52.  
  53.  Table of Contents .......................................... 2
  54.  
  55.  Archives ................................................... 3
  56.  
  57.  Dates and Times ............................................ 5
  58.  
  59.  Equipment Info ............................................. 6
  60.  
  61.  Extended Math .............................................. 9
  62.  
  63.  Graphics .................................................. 12
  64.  
  65.  Keyboard .................................................. 15
  66.  
  67.  Memory (EMS) .............................................. 19
  68.  
  69.  Memory (XMS) .............................................. 22
  70.  
  71.  Mouse Support ............................................. 24
  72.  
  73.  Strings ................................................... 27
  74.  
  75.  Credits ................................................... 30
  76.  
  77.                            Archives                      page 3
  78.  
  79.  
  80.  
  81. When I started in the microcomputer industry, there were a
  82. variety of file archivers, all (more or less) compatible.  They
  83. did not provide compression, which was relegated to another
  84. large selection of more-or-less compatible utilities.  Then
  85. came SEA's ARC.  It was very slow, but it did compression as
  86. well as archiving, and included CRC checks so you could know
  87. whether the files were intact.  It swept the BBS scene in short
  88. order, becoming the new standard.  A few other archivers
  89. competed on about a level footing, providing only minor
  90. variances on the ARC theme.  Then SEA decided to sue one of the
  91. more successful competitors, Phil Katz (PKARC).  The end result
  92. was the ZIP standard... but in the chaos resulting from the
  93. breaking of the ARC standard, many other archivers came into
  94. being: ARJ, LZH, PAK, ZOO, and so forth.
  95.  
  96. PBWiz helps resolve the confusion by providing a single set of
  97. routines which allow you to view the contents of archives in
  98. any of the above-mentioned formats: ARC, ARJ, LZH, PAK, ZIP, or
  99. ZOO.  Only archive directories are provided at this time.
  100. Other formats will also be added as they arise.  If you have
  101. details on the format of an archive that you'd like me to add,
  102. please send them my way.  I'll do what I can to get it into
  103. PBWiz.
  104.  
  105. This unit requires the STRING unit (discussed later) as well.
  106. To use it in your program, you need to include both units:
  107.  
  108.    $INCLUDE "string.inc"      ' (to use STRING yourself)
  109.    $INCLUDE "archives.inc"
  110.    $LINK "stringa.obj"
  111.    $LINK "stringb.pbu"
  112.    $LINK "archives.pbu"
  113.  
  114. Viewing archive directories is handled in roughly the same
  115. fashion as you might view a DOS file directory.  This makes it
  116. possible to treat an archive and a subdirectory in a similar
  117. manner.
  118.  
  119. When you're looking for the first file in an archive, use the
  120. FindFirstA function.  You must specify the archive name and a
  121. file name.  The archive name may include a drive and path
  122. specification, and does not need to have the archive
  123. extension.  If you leave off the extension, FindFirstA will use
  124. the first archive it comes across that matches the rest of the
  125. specification. Note that the archive specification may not
  126. contain wildcards.  In contrast, the search file name may not
  127. contain drive or path specs, but may contain wildcards.
  128.  
  129.    CALL FindFirstA (Archive$, Filename$, ErrCode%)
  130.  
  131.                                    Archives                      page 4
  132.  
  133.  
  134.  
  135. If there are no files to be found, or if the archive
  136. specification was bad, an error code will be returned.  If
  137. there was no error, there may well be more files to be found.
  138. You can find each of them with FindNextA:
  139.  
  140.    CALL FindNextA (ErrCode%)
  141.  
  142. Of course, just finding a matching file doesn't do you much
  143. good unless you can retrieve information about it.  You can use
  144. any of the following routines to provide information about a
  145. matched file:
  146.  
  147.    Nam$ = GetNameA$
  148.    Dat$ = GetDateA$
  149.    Tim$ = GetTimeA$
  150.    CRC$ = GetCRCA$
  151.    StorageMethod$ = GetStoreA$
  152.  
  153.    CALL GetSizeA (OriginalSize&, CurrentSize&)
  154.  
  155. When you're done viewing an archive, be sure to close it:
  156.  
  157.    CALL CloseA
  158.  
  159. Let's try an example.  Given that you've already written the
  160. $INCLUDE and $LINK lines as specified on the previous page, you
  161. could see all of the files in an archive using a program like
  162. this:
  163.  
  164.    CALL FindFirstA (Archive$, "*.*", ErrCode%)
  165.    DO UNTIL ErrCode%
  166.       PRINT GetNameA$
  167.       CALL FindNextA (ErrCode%)
  168.    LOOP
  169.    CALL FCloseA
  170.  
  171. This program fragment also assumes that you have set Archive$
  172. to the name of an archive.  It might be convenient to set it to
  173. the command line for testing purposes:
  174.  
  175.    Archive$ = UCASE$(LTRIM$(RTRIM$(COMMAND$)))
  176.  
  177.                         Dates and Times                  page 5
  178.  
  179.  
  180.  
  181. This unit allows you to validate and compare dates.  It also
  182. provides the day of the week, given the date.  Dates may not be
  183. before the year 1900.  Date strings may be in the form
  184. "01/01/91" or "01-01-1991" (the delimiter is not significant
  185. and years may be two or four digits; two-digit years will be
  186. assumed to be in the 20th century).
  187.  
  188. To use the routines in this unit, include the following lines
  189. at the top of your program:
  190.  
  191.    $INCLUDE "timedate.inc"
  192.    $LINK "timedate.pbu"
  193.  
  194. Let's start off with date validation.  It's often important to
  195. know if a date entered into your program is a valid date.
  196.  
  197.    IF GoodDate%(DateSt$) THEN PRINT "The date is valid."
  198.  
  199. It can also be helpful to know on which day of the week a given
  200. date falls.
  201.  
  202.    Day$ = WeekDay$(DateSt$)
  203.  
  204. There are many useful things you can accomplish by turning a
  205. date into a number which represents that date (or vice versa).
  206. This allows you to compare two dates, which is important if you
  207. want to sort by date; find out what the date will be in a given
  208. number of days, or what it was some number of days ago; find
  209. the number of days between two dates; display a calendar; and
  210. so forth.  This is easy to do with PBWiz:
  211.  
  212.    DateNr& = Date2Num&(DateSt$)
  213.  
  214.    DateSt$ = Num2Date$(DateNr&)
  215.  
  216. The DateNr& represents the number of days since January 1,
  217. 1900.  This is less than 65,535 for dates that go up to around
  218. the year 2070 or so, so you may wish to store the dates in
  219. compressed two-byte form if your required range of dates is not
  220. that large:
  221.  
  222.    CrunchDate% = CVI(LEFT$(MKL$(DateNr&), 2))
  223.  
  224. This can be reversed simply:
  225.  
  226.    DateNr& = CVL(MKI$(CrunchDate%) + STRING$(2, 0))
  227.  
  228. Note that dates crunched this way are only useful for storage
  229. purposes, since the numbers greater than 32,767 are stored as
  230. negative numbers due to the signed integer format BASIC uses.
  231. You must uncompress them before doing any comparisons or date
  232. calculations.  Still, for a savings of 50%, it may be worth the
  233. hassle to convert back and forth.
  234.  
  235.                         Equipment Info                   page 6
  236.  
  237.  
  238.  
  239. The equipment unit gives you information about the computing
  240. environment. This includes both installed software and
  241. hardware.  You can use the equipment information routines by
  242. including these lines in your program:
  243.  
  244.    $INCLUDE "equipmen.inc"
  245.    $LINK "equipmen.obj"
  246.  
  247. The first function allows you to determine if an "enhanced"
  248. keyboard (101-key) is installed.  It may not be able to figure
  249. out what the keyboard is on some older not-quite-clone PCs, in
  250. which case it will take the safe way out and report that there
  251. is no enhanced keyboard.  This function returns -1 if there is
  252. an enhanced keyboard present, 0 if not.
  253.  
  254.    Enhanced% = KbdType%
  255.  
  256. Want to know the type of processor (CPU) being used?  Can do!
  257.  
  258.    CPU% = Processor%
  259.  
  260. The results will be reported as a number which can be decoded
  261. as follows:
  262.  
  263.    0    NEC V20
  264.    1    8088 or 8086
  265.    2    80186
  266.    3    80286
  267.    4    80386 or 80486
  268.  
  269. If anyone knows how to differentiate between an 80386 and an
  270. 80486, please let me know.  I've only seen one test which could
  271. do it, and it wasn't reliable.
  272.  
  273. Maybe you'd like to check for a CD-ROM drive:
  274.  
  275.    Drives% = CDROM%
  276.  
  277. This tells you how many logical drives exist, if there is a
  278. CD-ROM available. If not, it will return 0.  Note that the
  279. CD-ROM installation check conflicts with the GRAPHICS.COM
  280. installation check for DOS 4.0, due to some screw-up at IBM or
  281. Microsoft.  I'm not yet sure whether DOS 5.0 is similarly
  282. afflicted.
  283.  
  284. The number of floppy drives installed is retrieved like this:
  285.  
  286.    Drives% = Floppies%
  287.  
  288.                         Equipment Info                   page 7
  289.  
  290.  
  291.  
  292. There may be up to four floppy drives in a system; however, the
  293. AT CMOS data area only directly supports two. This makes it
  294. easy to find out what kind of drives the first two are, but not
  295. the second two.  Oh well, guess we'll have to settle for what
  296. we can get, right?
  297.  
  298.    CALL FloppyType (Drive1, Drive2)
  299.  
  300. The results from FloppyType are returned as follows:
  301.  
  302.    0    no drive
  303.    1    5 1/4"    360K
  304.    2    5 1/4"    1.2M
  305.    3    3 1/2"    720K
  306.    4    3 1/2"    1.44M
  307.  
  308. Result codes of 5-7 are available, but not yet defined.  One
  309. might guess that the 2.88M drive supported by DOS 5.0 will be
  310. drive type 5.  Has anybody seen one of those puppies yet?
  311.  
  312. New memory types sure have burgeoned over the years...
  313. expanded, extended, and now XMS.  There are routines to check
  314. all of these:
  315.  
  316.    BaseExt& = AllExtMem&     ' extended memory installed
  317.    NowExt& = GetExtM&        ' BIOS extended memory available
  318.  
  319.    CALL GetEMSm (TotalPages%, FreePages%)    ' expanded memory
  320.  
  321.    CALL GetXMSm (LargestFree&, TotalFree&)   ' XMS memory
  322.  
  323. When you're dealing with extended memory, whether it be
  324. BIOS-type or using the XMS standard, the results are returned
  325. in kilobytes.  Multiply 'em by 1024 to convert to bytes.  When
  326. you're dealing with expanded memory (EMS), the results are in
  327. pages of 16,384 bytes.
  328.  
  329. I might note, by the way, that Microsoft seems to have
  330. intentionally crippled the XMS standard.  It can only support a
  331. maximum of 64 megabytes.  This may seem like a lot now, but I
  332. can remember when my first PC (a Compaq portable) was the awe
  333. of the neighborhood with 384K RAM!  A few years down the road,
  334. the artificial limitations of XMS are going to be a nuisance.
  335.  
  336. A few more routines to get the versions of the EMS and XMS
  337. drivers, if any:
  338.  
  339.    CALL GetEMSv (MajorV%, MinorV%)
  340.    CALL GetXMSv (MajorV%, MinorV%)
  341.  
  342. These return the major and minor version numbers as two
  343. separate integers. For example, EMS 4.0 would return major
  344. version 4, minor version 0.
  345.  
  346.                         Equipment Info                   page 8
  347.  
  348.  
  349.  
  350. It's nice to know a little about the operating environment.
  351. With the below routines, you can find out what the DOS version
  352. is; what version of 4DOS, if any, is in use; and whether
  353. Microsoft Windows is running.
  354.  
  355.    CALL GetDOSv (MajorV%, MinorV%)
  356.    CALL Get4DOSv (MajorV%, MinorV%)
  357.    CALL WinCheck (MajorV%, MinorV%)
  358.  
  359. These return results as major and minor version numbers, as
  360. discussed on the previous page.  The Get4DOSv and WinCheck
  361. routines return zeroes if 4DOS and Windows, respectively, are
  362. not available.
  363.  
  364. There are a couple of curious features of GetDOSv to keep in
  365. mind.  If the version is 10 or higher, you're running in OS/2
  366. compatibility mode.  DOS version 10 is actually OS/2 1.0,
  367. version 20 is OS/2 2.0, and so on. Secondly, if you're using
  368. DOS 5.0, the version reported may not be 5.0-- DOS 5.0 can be
  369. told to reply with a lower version number to allow some older
  370. software (which checks for a specific DOS version) to run
  371. properly.
  372.  
  373. One final routine that should be of some value is the one that
  374. allows you to find out what kind of display is available.  It
  375. tells you the specific adapter and whether the display is color
  376. or monochrome.  There is one case in which it can be confused,
  377. however-- if the adapter is CGA, the display is assumed to be
  378. color, since there is no way for the computer to know any
  379. differently.  So, although this routine provides a good idea of
  380. what is available, it would be a good idea to provide an option
  381. to tell the program that a monochrome display is attached.
  382. Microsoft normally uses "/B" for this purpose, so that might be
  383. a good standard to stick with.
  384.  
  385.    CALL GetDisplay (Adapter%, Mono%)
  386.    IF Mono% THEN
  387.       PRINT "Monochrome monitor"
  388.    ELSE
  389.       PRINT "Color monitor"
  390.    END IF
  391.    SELECT CASE Adapter%
  392.       CASE 1: PRINT "MDA"
  393.       CASE 2: PRINT "Hercules"
  394.       CASE 3: PRINT "CGA"
  395.       CASE 4: PRINT "EGA"
  396.       CASE 5: PRINT "MCGA"
  397.       CASE 6: PRINT "VGA"
  398.    END SELECT
  399.  
  400.                          Extended Math                   page 9
  401.  
  402.  
  403.  
  404. The extended math unit provides an expression evaluator and
  405. extensions to BASIC's math.  The math extensions include
  406. hyperbolic and inverse trig functions, a few handy constants,
  407. conversions, and more.  You can use the new math routines by
  408. including this at the top of your program:
  409.  
  410.    $INCLUDE "extmath.inc"
  411.    $LINK "extmath.pbu"
  412.  
  413. The expression evaluator allows you to find the result of an
  414. expression contained in a string.  Normal algebraic precedence
  415. is used, e.g. 4+3*5 evaluates to 19.  The usual numeric
  416. operators (*, /, +, -, ^) are supported (multiply, divide, add,
  417. subtract, and raise to a power).  Use of negative numbers is
  418. just fine, of course.  Parentheses for overriding the default
  419. order of operations are also supported.
  420.  
  421. You may use either a double asterisk ("**") or a caret ("^")
  422. symbols to indicate exponentiation.
  423.  
  424. To evaluate an expression, you pass it to the evaluator as a
  425. string.  You will get back either an error code or a
  426. single-precision result.  Try this example to see how the
  427. expression evaluator works:
  428.  
  429.    $STACK 4096
  430.    $INCLUDE "extmath.inc"
  431.    $LINK "extmath.pbu"
  432.    DO
  433.       INPUT "Expression? "; Expr$
  434.       IF LEN(Expr$) THEN
  435.          CALL Evaluate (Expr$, Result!, ErrCode%)
  436.          IF ErrCode% THEN
  437.             PRINT "Invalid expression.  Error = "; ErrCode%
  438.          ELSE
  439.             PRINT "Result: "; Result!
  440.          END IF
  441.       END IF
  442.    LOOP WHILE LEN(Expr$)
  443.    END
  444.  
  445. An expression evaluator adds convenience to any program that
  446. needs to accept numbers.  Why make someone reach for a
  447. calculator when number crunching is what a computer does best?
  448.  
  449. NOTE: The expression evaluator uses recursion and will require
  450. more than the default amount of stack space.  That's why the
  451. $STACK metacommand is used.
  452.  
  453.                          Extended Math                  page 10
  454.  
  455.  
  456.  
  457. The new math functions are pretty much self-explanatory, so
  458. I'll just list them here.  A few general notes are given on the
  459. next page.
  460.  
  461.    Result% = GCDI%(Nr1%, Nr2%)   ' greatest common denominator
  462.  
  463.    Result& = GCDL&(Nr1&, Nr2&)   ' greatest common denominator
  464.  
  465.    Result! = ArcCosHS!(Nr!)      ' inverse hyperbolic cosine
  466.    Result! = ArcSinHS!(Nr!)      ' inverse hyperbolic sine
  467.    Result! = ArcTanHS!(Nr!)      ' inverse hyperbolic tangent
  468.    Result! = ArcCosS!(Nr!)       ' arc cosine  (1 >= Nr >= -1)
  469.    Result! = ArcSinS!(Nr!)       ' arc sine    (1 >= Nr >= -1)
  470.    Result! = ErfS!(Nr!)          ' error function
  471.    Result! = FactS!(Nr%)         ' factorial
  472.    Result! = CotS!(Nr!)          ' cotangent
  473.    Result! = CscS!(Nr!)          ' cosecant
  474.    Result! = SecS!(Nr!)          ' secant
  475.    Result! = CosHS!(Nr!)         ' hyperbolic cosine
  476.    Result! = SinHS!(Nr!)         ' hyperbolic sine
  477.    Result! = TanHS!(Nr!)         ' hyperbolic tangent
  478.    Result! = Deg2RadS!(Nr!)      ' convert degrees to radians
  479.    Result! = Rad2DegS!(Nr!)      ' convert radians to degrees
  480.    Result! = Cent2Fahr!(Nr!)     ' centigrade to Fahrenheit
  481.    Result! = Fahr2Cent!(Nr!)     ' Fahrenheit to centigrade
  482.    Result! = Kg2Pound!(Nr!)      ' convert kilograms to pounds
  483.    Result! = Pound2Kg!(Nr!)      ' convert pounds to kilograms
  484.    Pi! = PiS!                    ' the constant "pi"
  485.    e! = eS!                      ' the constant "e"
  486.  
  487.    Result# = ArcCosHD#(Nr#)      ' inverse hyperbolic cosine
  488.    Result# = ArcSinHD#(Nr#)      ' inverse hyperbolic sine
  489.    Result# = ArcTanHD#(Nr#)      ' inverse hyperbolic tangent
  490.    Result# = ArcCosD#(Nr#)       ' arc cosine  (1 >= Nr >= -1)
  491.    Result# = ArcSinD#(Nr#)       ' arc sine    (1 >= Nr >= -1)
  492.    Result# = ErfD#(Nr#)          ' error function
  493.    Result# = FactD#(Nr%)         ' factorial
  494.    Result# = CotD#(Nr#)          ' cotangent
  495.    Result# = CscD#(Nr#)          ' cosecant
  496.    Result# = SecD#(Nr#)          ' secant
  497.    Result# = CosHD#(Nr#)         ' hyperbolic cosine
  498.    Result# = SinHD#(Nr#)         ' hyperbolic sine
  499.    Result# = TanHD#(Nr#)         ' hyperbolic tangent
  500.    Result# = Deg2RadD#(Nr#)      ' convert degrees to radians
  501.    Result# = Rad2DegD#(Nr#)      ' convert radians to degrees
  502.    Pi# = PiD#                    ' the constant "pi"
  503.    e# = eD#                      ' the constant "e"
  504.  
  505.                          Extended Math                  page 11
  506.  
  507.  
  508.  
  509. Like BASIC's trig functions, these trig functions expect the
  510. angle to be in radians.  Conversion functions are provided in
  511. case you prefer degrees.
  512.  
  513. Note that there is no ArcTanS! or ArcTanD# function for the
  514. simple reason that BASIC supplies an ATN function.
  515.  
  516. Constants are expressed to the maximum precision available.
  517.  
  518. If you are not familiar with variable postfix symbols, here's a
  519. brief summary:
  520.  
  521.    Symbol   Meaning             Range (approximate)
  522.    ------   --------            -------------------------------
  523.      %      integer             +- 32767
  524.      &      long integer        +- 2 * 10^9
  525.      !      single precision    +- 1 * 10^38
  526.      #      double precision    +- 1 * 10^308
  527.  
  528. See PowerBASIC's online help for further details.
  529.  
  530.                        Graphics Support                 page 12
  531.  
  532.  
  533.  
  534. I was rather surprised to find that PowerBASIC lacks support
  535. for one of the standard VGA modes-- SCREEN 13, the 320x200
  536. 256-color mode.  I immediately decided to add support for that
  537. mode: dots, lines, boxes, polygons, and (of course) text.
  538. While I was at it, I thought I'd add support for a nonstandard
  539. VGA mode: 360x480 in 256 colors.  This mode will work on almost
  540. any plain VGA system, although it might not work on some older
  541. not-quite-compatible setups. I'll be adding other modes as I go
  542. along, including SuperVGA modes.  For now, there are only two
  543. modes:
  544.  
  545.    13    320x200, 256 colors, 40x25 text, any VGA
  546.    N0    360x480, 256 colors, 45x60 text, almost any VGA
  547.  
  548. The graphics routines all use the same nomenclature: a G,
  549. followed by a mode number, followed by the specific name.  This
  550. generic naming convention is used so that this chapter can
  551. refer to all available modes.  For example, if I say "G#Color"
  552. and you're using mode 13, you'd actually use "G13Color" in your
  553. program.  Ok?
  554.  
  555. There are two sets of routines for each mode-- the ones written
  556. in ASM and the ones written in BASIC.  The file names for these
  557. will be suffixed with "A" for ASM and "B" for BASIC.  For
  558. instance, to use the SCREEN 13 routines, you would add the
  559. following at the top of your program:
  560.  
  561.    $INCLUDE "g13.inc"
  562.    $LINK "g13a.obj"
  563.    $LINK "g13b.pbu"
  564.  
  565. The first thing you will always have to do is to put the screen
  566. into the proper mode.  This is done with the G#Mode routine:
  567.  
  568.    CALL G#Mode (Graphics%)
  569.  
  570. Use 0 to switch to text mode or any other value to switch to
  571. graphics mode.
  572.  
  573. One difference between BASIC and BasWiz is that, instead of
  574. each "draw" command requiring a color parameter as in BASIC,
  575. the PBWiz library provides a separate color command:
  576.  
  577.    CALL G#Color (Foreground%, Background%)
  578.  
  579. The "foreground" color is used by all graphics routines.  The
  580. background color is used by the G#Cls routine.  Both foreground
  581. and background colors are used in the G#Write and G#WriteLn
  582. routines.
  583.  
  584.                        Graphics Support                 page 13
  585.  
  586.  
  587.  
  588. Here is a list of the corresponding routines, first BASIC, then
  589. PBWiz (replace the "#" with the appropriate mode number):
  590.  
  591.    ' get the color of a specified point
  592.    colour% = POINT(x%, y%)
  593.    colour% = G#GetPel%(x%, y%)
  594.  
  595.    ' set the color of a specified point
  596.    PSET (x%, y%), colour%
  597.    CALL G#Color (colour%, backgnd%): CALL G#Plot (x%, y%)
  598.  
  599.    ' draw a line of a specified color
  600.    LINE (x1%, y1%) - (x2%, y2%), colour%
  601.    CALL G#Color (colour%, backgnd%)
  602.    CALL G#Line (x1%, y1%, x2%, y2%)
  603.  
  604.    ' draw a box frame of a specified color
  605.    LINE (x1%, y1%) - (x2%, y2%), colour%, B
  606.    CALL G#Color (colour%, backgnd%)
  607.    CALL G#Box (x1%, y1%, x2%, y2%, 0)
  608.  
  609.    ' draw a box of a specified color and fill it in
  610.    LINE (x1%, y1%) - (x2%, y2%), colour%, BF
  611.    CALL G#Color (colour%, backgnd%)
  612.    CALL G#Box (x1%, y1%, x2%, y2%, 1)
  613.  
  614.    ' clear the screen and home the cursor
  615.    CLS
  616.    CALL G#Cls
  617.  
  618.    ' get the current cursor position
  619.    Row% = CSRLIN: Column% = POS(0)
  620.    CALL G#GetLocate (Row%, Column%)
  621.  
  622.    ' set the current cursor position
  623.    LOCATE Row%, Column%
  624.    CALL G#Locate (Row%, Column%)
  625.  
  626.    ' display a string without a carriage return and linefeed
  627.    PRINT St$;
  628.    CALL G#Write (St$)
  629.  
  630.    ' display a string with a carriage return and linefeed
  631.    PRINT St$
  632.    CALL G#WriteLn (St$)
  633.  
  634. Note that PBWiz, unlike BASIC, allows both foreground and
  635. background colors for text in graphics mode.
  636.  
  637.                        Graphics Support                 page 14
  638.  
  639.  
  640.  
  641. If you need to print a number rather than a string, just use
  642. the BASIC function STR$ to convert it.  If you don't want a
  643. leading space, use this approach:
  644.  
  645.    St$ = LTRIM$(STR$(Number))
  646.  
  647. The PBWiz library has other routines which have no BASIC
  648. equivalent.  One allows you to get the current colors:
  649.  
  650.    CALL G#GetColor (Foreground%, Background%)
  651.  
  652. Circles and ellipses can be drawn with the Ellipse routine.
  653. This is similar to the BASIC CIRCLE statement.  You specify the
  654. center of the ellipse (X,Y), plus the X and Y radius values:
  655.  
  656.    CALL G#Ellipse (CenterX%, CenterY%, XRadius%, YRadius%)
  657.  
  658. A circle is an ellipse with a constant radius.  So, to draw a
  659. circle, just set both radius values to the same value.
  660.  
  661. As well as the usual points, lines, and ellipses, PBWiz also
  662. allows you to draw regular polygons: triangles, squares,
  663. pentagons, hexagons, and so on.
  664.  
  665.    CALL G#Polygon (X%, Y%, Radius%, Vertices%, Angle!)
  666.  
  667. The X% and Y% values represent the coordinates of the center of
  668. the polygon. The Radius% is the radius of the polygon (as if
  669. you were fitting it into a circle).  Vertices% is the number of
  670. angles (also the number of sides) for the polygon to have.
  671. Angle! specifies the rotation of the polygon, and is specified
  672. in radians.
  673.  
  674.                        Keyboard Control                 page 15
  675.  
  676.  
  677.  
  678. The keyboard is not a particularly exciting or glamorous
  679. device.  In fact, we tend to forget about it except when it
  680. gets in the way.  Sometimes it's a hardware problem-- squishy
  681. or clacking keys, or perhaps a commonly-used key placed in an
  682. out-of-the-way location.  Then again, sometimes it's the
  683. software that's the problem.  There are many aspects of
  684. keyboard control, not all of which are necessarily related to
  685. input.  This unit will let you handle the keyboard in ways you
  686. may not have realized were possible.  Better yet, it can help
  687. make keyboard control easier than the users of your programs
  688. dreamed possible.  It all starts with the two little lines:
  689.  
  690.    $INCLUDE "keyboard.inc"
  691.    $LINK "keyboard.obj"
  692.  
  693. Let's start out with keyboard output.  Yep, not input--
  694. output.  We can stuff up to 15 keys into the keyboard buffer.
  695. Why would we ever want to do this? Perhaps to allow your
  696. program to pop-up a TSR automatically, to start another program
  697. after your program ends, or for creating key macros.  You can
  698. enter extended key codes (such as function keys) by using
  699. CHR$(0) before the scan code.
  700.  
  701.    CALL TypeIn (St$)
  702.  
  703. The usual keyboard action is somewhat sluggish.  We can make it
  704. a lot crisper by changing the key repeat rate and the delay
  705. before repeating begins.  This will work on ATs, but not PC/XT
  706. systems.
  707.  
  708.    CALL SpeedKey (RepDelay%, RepRate%)
  709.  
  710. The delay may be 0-3 (1 by default):
  711.  
  712.    0      250 milliseconds
  713.    1      500 milliseconds
  714.    2      750 milliseconds
  715.    3        1 second
  716.  
  717. The repeat rate may be 0-31 (11 by default).  The larger the
  718. number, the slower the speed-- 0 is around 30 cps, and 31 is
  719. around 2 cps.
  720.  
  721. I generally prefer to have the keyboard cranked up to full
  722. speed, using RepDelay% and RepRate% both set to zero.  This may
  723. be a bit too zippy for some people.  Experiment with it to see
  724. what you like best.
  725.  
  726. Of course, there may be reasons to make keyboard repeat less
  727. sensitive instead!  That might be a good idea in programs
  728. written for small children, for example.  You can adjust the
  729. keyboard equally well in either direction.
  730.  
  731.                        Keyboard Control                 page 16
  732.  
  733.  
  734.  
  735. PowerBASIC allows you to control one of the keys which can
  736. interrupt your program, namely the Break key.  There's another
  737. dangerous key which PBWiz allows you to control-- the PrtSc
  738. (PrintScreen) key.  PrtSc may not seem like a hazard at first
  739. glance, but if it's pressed by accident with no printer ready,
  740. or in a graphics mode which PrtSc doesn't understand how to
  741. print, the results can be pretty messy.  So, we let you turn it
  742. off or back on:
  743.  
  744.    CALL SetPrtSc (PrtScON%)
  745.  
  746. Use 0 to turn it off or anything else to turn it back on.  If
  747. you turn off PrtSc, you MUST remember to turn it back on again
  748. before your program ends! Otherwise, an interrupt vector will
  749. point into nowhere, causing probable chaos the next time PrtSc
  750. is pressed.
  751.  
  752. Regardless of whether you've turned the PrtSc key off, you can
  753. print the screen yourself just as if PrtSc had been pressed:
  754.  
  755.    CALL PrintScreen
  756.  
  757. Now here's a strange one for you.  When IBM brought out the
  758. 101-key keyboard, called the "enhanced" keyboard, they did
  759. something bizarre to the BIOS.  They still allowed old keyboard
  760. calls to work, but they filtered out the new key codes so no
  761. one would see them.  This made sure that no one would be able
  762. to use the capabilities of the "enhanced" keyboard without
  763. rewriting their programs.  So, the keyboard has been around for
  764. years, and there are still few programs that even notice when
  765. you press F11.  PowerBASIC v2.1 does not support the enhanced
  766. keyboard at all.  Fortunately, PBWiz -does-.  You can find out
  767. if an enhanced keyboard is installed with the KbdType%
  768. function, which is in the Equipment unit.
  769.  
  770. If there is an enhanced keyboard installed, you can activate it
  771. like so:
  772.  
  773.    CALL SetEnhKbd (Enhanced%)
  774.  
  775. With enhanced keyboard support activated, all key requests that
  776. used the old services are translated to the new services.  So,
  777. SetEnhKbd affects INKEY$ and other BASIC functions as well as
  778. other PBWiz keyboard routines.  Note that you MUST deactivate
  779. enhanced keyboard support before ending your program.
  780. Otherwise, an interrupt vector will point into nowhere,
  781. probably causing a crash on the next keypress!
  782.  
  783.                        Keyboard Control                 page 17
  784.  
  785.  
  786.  
  787. Speaking of INKEY$, I have a neat little function for you.  It
  788. works like INKEY$, but it doesn't remove the key from the
  789. keyboard buffer:
  790.  
  791.    ky$ = ScanKey$
  792.  
  793. How is this handy?  Well, let's suppose you're writing
  794. something that will work like the DIR or TYPE commands in DOS.
  795. It will display what may be a long listing, which you'd like to
  796. be able to pause with Ctrl-S or cancel with Ctrl-C.  Trouble
  797. is, if you use INKEY$ and the user was using "type ahead" to
  798. store another command, you've just wiped out his command while
  799. looking for those control codes.  With ScanKey$, you can check
  800. the key nondestructively.
  801.  
  802. On the other hand, if you're about to request important input,
  803. you may not want to chance having it answered from results of
  804. the keyboard buffer-- could be that the user meant those keys
  805. for another purpose.  In that case, it's a good approach to
  806. clear out the keyboard buffer just before the input:
  807.  
  808.    CALL ClearKbd
  809.  
  810. No keyboard unit would be complete without a selection of
  811. routines to check the shift states and get or set the keyboard
  812. toggles.  Let's start with the toggles, which are so called
  813. because they get toggled from one state to another:
  814.  
  815.     PRINT "Caps Lock  : ";
  816.     IF CapsOn% THEN PRINT "ON" ELSE PRINT "OFF"
  817.     PRINT "Insert     : ";
  818.     IF InsertOn% THEN PRINT "ON" ELSE PRINT "OFF"
  819.     PRINT "Num Lock   : ";
  820.     IF NumOn% THEN PRINT "ON" ELSE PRINT "OFF"
  821.     PRINT "Scroll Lock: ";
  822.     IF ScrollOn% THEN PRINT "ON" ELSE PRINT "OFF"
  823.  
  824. You can also turn the toggles off or on.  It's courteous to
  825. restore the original toggle states once you end your program,
  826. so you might want to save the original values for that
  827. purpose.  Then again, I guess that doesn't apply if your
  828. program is designed for the specific purpose of setting the
  829. toggles!
  830.  
  831.    CALL SetCaps (CapsLock%)
  832.    CALL SetInsert (InsertKey%)
  833.    CALL SetNum (NumLock%)
  834.    CALL SetScroll (ScrollLock%)
  835.  
  836. Does anyone actually use ScrollLock for anything?  Just
  837. wondering...
  838.  
  839.                        Keyboard Control                 page 18
  840.  
  841.  
  842.  
  843. The shift keys are unique in many respects.  They don't return
  844. codes that can be detected with INKEY$ or stuffed into the
  845. keyboard buffer; several can be pressed at the same time; and
  846. they don't repeat.  You can detect 'em with PBWiz, at any rate:
  847.  
  848.    IF AltPress% THEN PRINT "An ALT key is pressed."
  849.    IF CtrlPress% THEN PRINT "A CTRL key is pressed."
  850.    IF ShiftPress% THEN PRINT "A SHIFT key is pressed."
  851.  
  852.    IF LAltPress% THEN PRINT "The LEFT ALT key is pressed."
  853.    IF LCtrlPress% THEN PRINT "The LEFT CTRL key is pressed."
  854.    IF LShiftPress% THEN PRINT "The LEFT SHIFT key is pressed."
  855.  
  856.    IF RAltPress% THEN PRINT "The RIGHT ALT key is pressed."
  857.    IF RCtrlPress% THEN PRINT "The RIGHT CTRL key is pressed."
  858.    IF RShiftPress% THEN PRINT "The RIGHT SHIFT key is pressed."
  859.  
  860. NOTE that LAltPress%, LCtrlPress%, RAltPress%, and RCtrlPress%
  861. are ONLY available for enhanced keyboards.  They will not
  862. return useful results on older keyboards.
  863.  
  864.                          Memory (EMS)                   page 19
  865.  
  866.  
  867.  
  868. This unit provides support for expanded memory.  It will work
  869. with older EMS and EEMS drivers as well as the current EMS 4.0
  870. standard, with the exception of one or two routines (as noted)
  871. which take advantage of new capabilities.
  872.  
  873. Expanded memory may be present on any type of computer, from
  874. 8088 PCs to 80486 ATs.  It usually comes as a hardware board
  875. with a software driver for older machines; on ATs, it may be
  876. implemented using only a software driver which converts it from
  877. extended memory.  Drivers have also been written which make a
  878. hard disk function as EMS memory.  This broad range of use
  879. makes EMS support invaluable to programs which need extra
  880. memory.  EMS can theoretically support up to 1 gigabyte of RAM,
  881. although the documented limit as of v4.0 was only 32 megabytes.
  882.  
  883. This unit is called EMS.  You can access it by including these
  884. lines at the top of your program:
  885.  
  886.    $INCLUDE "ems.inc"
  887.    $LINK "ems.obj"
  888.  
  889. Of course, the first thing you need to know is whether any EMS
  890. memory actually exists:
  891.  
  892.    IF EMSexists% THEN PRINT "EMS exists"
  893.  
  894. The EMS version may also be retrieved:
  895.  
  896.    CALL EMSver (MajorV%, MinorV%)
  897.  
  898. It would be a good idea to check the EMS version if you plan to
  899. use any features which are only available as of EMS 4.0, such
  900. as reallocation.
  901.  
  902. Besides a mere existence and version checks, you will want to
  903. know how much EMS is available:
  904.  
  905.    PRINT "Total EMS installed: "; EMStotal%
  906.    PRINT "Free EMS memory    : "; EMSfree%
  907.  
  908. If you actually tried the above two lines, you would get a pair
  909. of values which don't seem to mean much.  The trick is to
  910. multiply them by 16,384 to convert them to bytes.  This is
  911. because EMS memory is always accessed in pages of 16k bytes
  912. each.  Any time you are dealing with a quantity of EMS memory,
  913. the quantity will be specified as a number of pages.
  914.  
  915.                          Memory (EMS)                   page 20
  916.  
  917.  
  918.  
  919. Before we get into the mechanics of accessing EMS memory, I'd
  920. like to bring up an optional routine which can improve access
  921. speed.  It should not be used if your program accesses EMS
  922. using routines other than the ones included here in PBWiz.  If
  923. you only use these EMS routines, though, you will find that it
  924. makes some kinds of memory accesses faster.  Use 0 for normal
  925. (slow) mode.  Do not use optimization if you are using more
  926. than one EMS handle!
  927.  
  928.    CALL EMSopt (Fast%)
  929.  
  930. Ok, let's get down to the nitty gritty.  (Where did that
  931. expression come from, anyway?!)  When you allocate EMS memory,
  932. you specify the number of pages you want, which must be at
  933. least 1.  If the allocation is successful, you are returned a
  934. "handle" which you can use to access the allocated memory.
  935. Otherwise, you get back an error code.
  936.  
  937.    CALL EMSopen (Pages%, Handle%, ErrCode%)
  938.  
  939. There are a limited number of handles available under some EMS
  940. drivers.  The EMS spec, as of v4.0, allowed for a maximum of
  941. 255 handles, and it's not unusual for a driver to support only
  942. 20 or so.  Bearing in mind that some of these handles may be
  943. used up by other applications, such as RAMdisks and caches,
  944. this really doesn't allow much leeway.  Try to use as few
  945. handles as possible!  You may well need to store multiple
  946. values in different areas of the memory allocated for a single
  947. handle, rather than allocating a new area of memory for each
  948. value.
  949.  
  950. Suppose you find you need more memory than you first
  951. allocated?  Or maybe less memory?  Well, provided EMS 4.0 or
  952. later is in use, you can reallocate the block:
  953.  
  954.    CALL EMSresize (Handle%, Pages%, ErrCode%)
  955.  
  956. There is no way to reallocate memory under older versions of
  957. EMS.  About the best you could do in that case would be to
  958. allocate a new area of the desired size, copy over the relevant
  959. data from the old area, and then deallocate the original area.
  960. Of course, this assumes that there is enough memory available
  961. to hold both areas, at least temporarily.
  962.  
  963. When you are finished using EMS, you must be sure to return the
  964. memory you allocated to the system.  It is IMPORTANT to do this
  965. before ending your program.  Otherwise, the memory you
  966. allocated will be "lost" until the next time you boot the
  967. computer.  Return the memory for each handle as follows:
  968.  
  969.    CALL EMSclose (Handle%)
  970.  
  971.                          Memory (EMS)                   page 21
  972.  
  973.  
  974.  
  975. Hmmmm... we've covered EMS detection, status info, allocating
  976. memory, freeing memory, resizing memory... what's missing
  977. here?  Ah!  We haven't discussed how to actually access the
  978. memory!
  979.  
  980. Accessing EMS memory is quite simple, but it involves a couple
  981. of steps.  EMS is mapped into a 64k block in the low area of
  982. memory (the area under 1M, which can be directly accessed).
  983. Since a page is 16k, the EMS block can hold up to four pages at
  984. a time.  To transfer data between normal memory and EMS memory,
  985. you must map the appropriate page(s) of EMS into the EMS
  986. block.  This is done like so:
  987.  
  988.     CALL EMSmap (Handle%, PPage%, VPage%)
  989.  
  990. The PPage% is the physical page, that is, the page number
  991. within the EMS block (0-3).  The VPage% is the virtual page,
  992. which is the number of a page within the EMS memory associated
  993. with Handle%.
  994.  
  995. Once you've mapped the desired virtual page into a physical
  996. page, it can be accessed using standard PowerBASIC memory
  997. commands, such PEEK$ and POKE$. First, set the segment:
  998.  
  999.    DEF SEG=EMSseg&
  1000.  
  1001. The offset within a page may be 0-16,383.  To get the
  1002. appropriate offset within the EMS block, you must add the
  1003. offset of the page itself.  This may be calculated as follows:
  1004.  
  1005.    DataOffset& = OffsetWithinPage% + PageNumber% * 16384&
  1006.  
  1007. One final note: for best compatibility, it would be good to
  1008. avoid using physical page 3 (the last 16k of the EMS block).
  1009. Some EMS drivers don't handle this page with complete accuracy,
  1010. for technical reasons I'm not going to get into right now.
  1011.  
  1012.                          Memory (XMS)                   page 22
  1013.  
  1014.  
  1015.  
  1016. This unit provides support for XMS extended memory.  It won't
  1017. work with extended memory unless an XMS driver is present.
  1018.  
  1019. Extended memory is only present in AT-class computers.  It is
  1020. not available on older PCs.  An XMS driver must also be used.
  1021. XMS drivers are included with MS-DOS 5.0 and Windows 3.0, among
  1022. other things, so this is not a major limitation.  XMS can
  1023. address a maximum of 64 megabytes.
  1024.  
  1025. This unit is called XMS.  You access it by including these
  1026. lines at the top of your program:
  1027.  
  1028.    $INCLUDE "xms.inc"
  1029.    $LINK "xms.obj"
  1030.  
  1031. The first thing to check is whether any XMS memory exists:
  1032.  
  1033.    IF XMSexists% THEN PRINT "XMS exists"
  1034.  
  1035. The XMS version may also be retrieved:
  1036.  
  1037.    CALL XMSver (MajorV%, MinorV%)
  1038.  
  1039. The amount of XMS memory available may be reported in either of
  1040. two different ways: total amount and largest available block.
  1041.  
  1042.    PRINT "Total XMS free    : "; XMStfree&
  1043.    PRINT "Largest free block: "; XMSlfree&
  1044.  
  1045. XMS memory is manipulated in terms of 1,024 byte blocks, so the
  1046. amount of free memory is reported in kilobytes.  Any time you
  1047. are dealing with a quantity of EMS memory, the quantity will be
  1048. specified as a number of 1K blocks, except as otherwise noted.
  1049.  
  1050.                          Memory (XMS)                   page 23
  1051.  
  1052.  
  1053.  
  1054. When you allocate XMS memory, you specify the number of
  1055. kilobytes that you want.  This may be 0-65535, in theory.
  1056. Dunno, I don't have 64M RAM <grin>. If the allocation is
  1057. successful, you are returned a "handle" which you can use to
  1058. access the allocated memory.  Otherwise, you get back an error
  1059. code.
  1060.  
  1061.    CALL XMSopen (KBytes&, Handle%, ErrCode%)
  1062.  
  1063. There are a limited number of handles available, although the
  1064. number can be controlled somewhat by a driver parameter.  It's
  1065. probably best to use as few handles as possible, to avoid
  1066. running out.  You may well want to store multiple values in
  1067. different areas of the memory allocated for a single handle,
  1068. rather than allocating a new area of memory for each value.
  1069.  
  1070. Suppose you find you need more memory than you first
  1071. allocated?  Or maybe less memory?  Just reallocate the block:
  1072.  
  1073.    CALL XMSresize (Handle%, KBytes&, ErrCode%)
  1074.  
  1075. When you are finished using XMS, you must be sure to return the
  1076. memory you allocated to the system.  It is IMPORTANT to do this
  1077. before ending your program.  Otherwise, the memory you
  1078. allocated will be "lost" until the next time you boot the
  1079. computer.  Return the memory for each handle as follows:
  1080.  
  1081.    CALL XMSclose (Handle%)
  1082.  
  1083. To transfer data between normal memory and XMS memory, you must
  1084. provide the segment and offset of the normal memory area (use
  1085. the PowerBASIC functions VARSEG and VARPTR to find the address
  1086. of a variable).  The position within XMS memory is specified as
  1087. a long-integer offset starting at zero.
  1088.  
  1089.     CALL XMSread (Handle%, Posn&, Bytes&, DSeg%, DOfs%)
  1090.  
  1091.     CALL XMSwrite (Handle%, Posn&, Bytes&, DSeg%, DOfs%)
  1092.  
  1093. Note that the Bytes& to transfer must be an EVEN NUMBER.  It is
  1094. not restricted to 64k, however, so you can transfer a great
  1095. deal of data with these routines.
  1096.  
  1097. The XMS spec guarantees a "reasonable" number of interrupt
  1098. windows during a transfer; however, it is possible that you
  1099. might experience some communications dropouts if you do large
  1100. transfers during high-speed telecommunications.  If this is
  1101. expected to happen, test it carefully.
  1102.  
  1103.                          Mouse Support                  page 24
  1104.  
  1105.  
  1106.  
  1107. The mouse unit provides full-featured mouse support.  You can
  1108. see if a mouse is available and how many buttons it has, get
  1109. the cursor position (either the current position or the
  1110. position at the last press or release of a specified button),
  1111. set the cursor position, change the cursor, set the mouse
  1112. range, get hardware information about the mouse, and so on.
  1113.  
  1114. This unit is called MOUSE, so you access it by including the
  1115. following lines at the top of your program:
  1116.  
  1117.    $INCLUDE "mouse.inc"
  1118.    $LINK "mouse.obj"
  1119.  
  1120. There are two unusual mouse modes to be aware of.  One is text
  1121. mode, which is mapped to a 640x200 virtual display.  So, to
  1122. convert the results to text format, you need to divide the
  1123. cursor position by eight and add one.  To convert from text
  1124. format, subtract one and multiply by eight.
  1125.  
  1126. The second unusual mode is 320x200 CGA mode, which is also
  1127. mapped to 640x200. To convert the coordinates to this mode,
  1128. divide X by two.  To convert from this mode, multiply the X
  1129. coordinate by two.
  1130.  
  1131. All other modes use the actual display coordinates instead of a
  1132. bizarro virtual screen.  Why the peculiar CGA and text modes?
  1133. Well, evidently Microsoft never thought there'd be any video
  1134. adapters besides MDA and CGA, and decided to create a single
  1135. virtual screen size that worked for all modes. Not a bad idea,
  1136. I guess, but rather shortsighted.  Oh well.
  1137.  
  1138. One other nuisance that you may run into is that the mouse
  1139. cursor can't be directly turned on or off.  A "cursor
  1140. visibility" count is maintained-- if the mouse cursor was
  1141. turned on twice, you'll need to turn it off twice before it
  1142. will actually disappear.
  1143.  
  1144. Before using the mouse, you must initialize it.  The
  1145. initialization routine also checks to make sure that a mouse is
  1146. installed and tells you how many buttons it has.  It's best to
  1147. initialize the mouse after setting the screen mode, so the
  1148. mouse driver understands what mode you're using.  Not all mouse
  1149. drivers support all screen modes, but you can reasonably expect
  1150. any current mouse driver to support MDA, CGA, EGA, and VGA.
  1151. Hercules graphics mode is rarely supported, as it must be set
  1152. through direct hardware access rather than the standard
  1153. techniques, so the mouse driver has little way of knowing that
  1154. you've changed the mode.
  1155.  
  1156. The mouse routines will work equally well with two-button or
  1157. three-button rodents.  The middle button functions will return
  1158. 0 with two-button mice.
  1159.  
  1160.                          Mouse Support                  page 25
  1161.  
  1162.  
  1163.  
  1164. I won't go into great detail on these routines, because they're
  1165. pretty much self-explanatory.  The mouse is a fairly easy
  1166. device to deal with.
  1167.  
  1168. You can initialize the mouse driver like so:
  1169.  
  1170.    Buttons% = MouseInit%
  1171.  
  1172. This returns the number of mouse buttons available.  If there
  1173. is no mouse, zero will be returned.  Initialize the mouse after
  1174. setting the screen mode.
  1175.  
  1176. You can make the mouse cursor visible or invisible.  It will
  1177. function just as well in either state.  See the previous page
  1178. for some quirks.
  1179.  
  1180.    CALL MouseShow       ' show the cursor
  1181.    CALL MouseHide       ' hide the cursor
  1182.  
  1183. There are many ways to get the mouse cursor position.  You can
  1184. get the current position, the position at which the mouse was
  1185. located when a particular button was pressed, or the position
  1186. when a button was released. If you choose a past position, you
  1187. can also find out how many presses or releases of the button
  1188. have taken place since you last checked.
  1189.  
  1190.    X% = MouseWhereX%                   ' current X coordinate
  1191.    Y% = MouseWhereY%                   ' current Y coordinate
  1192.  
  1193.    CALL MouseLClick (Count%, X%, Y%)   ' left presses & posn
  1194.    CALL MouseMClick (Count%, X%, Y%)   ' middle presses & posn
  1195.    CALL MouseRClick (Count%, X%, Y%)   ' right presses & posn
  1196.  
  1197.    CALL MouseLRelease (Count%, X%, Y%) ' left releases & posn
  1198.    CALL MouseMRelease (Count%, X%, Y%) ' middle releases & posn
  1199.    CALL MouseRRelease (Count%, X%, Y%) ' right releases & posn
  1200.  
  1201. If you'd prefer to find out which buttons are currently
  1202. pressed, no problem:
  1203.  
  1204.    Pressed% = MouseLButton%  ' whether left button is pressed
  1205.    Pressed% = MouseMButton%  ' whether middle button is pressed
  1206.    Pressed% = MouseRButton%  ' whether right button is pressed
  1207.  
  1208. Of course, you can also set the cursor location:
  1209.  
  1210.    CALL MouseLocate (X%, Y%)   ' set the mouse cursor position
  1211.  
  1212. The mouse cursor range can be restricted to a given area of the
  1213. screen.  This area is expressed by giving the upper left corner
  1214. and lower right corner of the rectangular area to which to
  1215. restrict the cursor.
  1216.  
  1217.    CALL MouseWindow (X1%, Y1%, X2%, Y2%)
  1218.  
  1219.                          Mouse Support                  page 26
  1220.  
  1221.  
  1222.  
  1223. There are a variety of cursor shapes available for graphics
  1224. mode:
  1225.  
  1226.     0    hourglass ("please wait, program is working" symbol)
  1227.     1    pointing arrow (default)
  1228.     2    pointing hand
  1229.     3    crosshair
  1230.     4    target (box in a box)
  1231.     5    grabbing hand
  1232.  
  1233. If you have ideas for more, let me know and I'll see what I can
  1234. do.  Cursor shapes are not unduly difficult to define.
  1235.  
  1236. The cursor image is set like so:
  1237.  
  1238.    CALL MouseCursorG (CursorNr%)
  1239.  
  1240.                             Strings                     page 27
  1241.  
  1242.  
  1243.  
  1244. One of the true strengths of BASIC lies in its powerful string
  1245. handling capability.  I'd be remiss if I didn't provide
  1246. extensions which improve it even further.  This unit can be
  1247. accessed by including these lines at the top of your program:
  1248.  
  1249.    $INCLUDE "string.inc"
  1250.    $LINK "stringa.obj"
  1251.    $LINK "stringb.pbu"
  1252.  
  1253. The simplest of the PBWiz string routines may seem somewhat
  1254. whimsical, but it has proven useful to me on several occasions
  1255. in the past.  It reverses the order of characters in a string.
  1256.  
  1257.    CALL Reverse (St$)
  1258.  
  1259. One of the places this has come in useful is in searching a
  1260. string from the end-- a reverse INSTR routine:
  1261.  
  1262.    CALL RInstr (MainSt$, SubSt$, Posn%)
  1263.  
  1264. Rather than returning the first occurrence of a substring
  1265. within a main string, it returns the last occurrence.  Another
  1266. handy string search allows you to search for various types of
  1267. characters, rather than a specific substring:
  1268.  
  1269.    CALL TInstr (MainSt$, Types%, Posn%)
  1270.  
  1271. The type(s) may be specified using any combination of the
  1272. following.  Just add them together.
  1273.  
  1274.     1    alphabetic
  1275.     2    numeric
  1276.     4    symbolic
  1277.     8    control
  1278.    16    graphics
  1279.    32    space
  1280.  
  1281. Since you can search for any specific types, you can also
  1282. readily invert the search to look for any characters that are
  1283. NOT of a given type or types:
  1284.  
  1285.    Types% = NOT Types%
  1286.  
  1287. This gives you complete control.  A typical use for TInstr
  1288. might be to clean up user input and make sure that it's valid.
  1289. It's also good for parsing.
  1290.  
  1291.                             Strings                     page 28
  1292.  
  1293.  
  1294.  
  1295. Another routine that is useful for cleaning up and parsing user
  1296. input is called Crunch.  It allows you to eliminate adjacent
  1297. duplicates of a character or list of characters.  One use for
  1298. this, for instance, would be to eliminate repeated spaces,
  1299. converting an input string from "*.*    *.BAK  /B" to a more
  1300. manageable "*.* *.BAK /B".
  1301.  
  1302.    Result$ = Crunch$(St$, CharList$)
  1303.  
  1304. There are a pair of routines that you'll find valuable if you
  1305. need to check the validity of a string.  These are designed to
  1306. be compatible with the Xmodem and Ymodem file transfer
  1307. protocols, so you can use them for error checking in
  1308. telecommunications as well.
  1309.  
  1310.    Chk% = CheckSum% (St$)
  1311.  
  1312.    CALL CRC16 (St$, HiCRC%, LoCRC%)
  1313.  
  1314. Another pair of string routines provide a simple
  1315. encryption/decryption system for text.  The method used is not
  1316. particularly secure but are very fast and will be adequate for
  1317. many purposes.  As always, it helps to use a long and/or
  1318. complex password.
  1319.  
  1320.    CALL Cipher (St$, Password$)
  1321.    CALL CipherP (St$, Password$)
  1322.  
  1323. Both of these routines will encipher text on the first
  1324. run-through and decipher on the second, so you can use the same
  1325. routine either to encrypt or decrypt a message.  They are
  1326. different in one respect: the encrypted result of Cipher may
  1327. contain control characters, so it can't be used in a plain
  1328. sequential-access file.  The CipherP routine does not allow use
  1329. of extended ASCII characters (CHR$(128) - CHR$(255)), as it
  1330. sets the high bit on each character after encrypting it.  This
  1331. causes the results of CipherP to be printable (and useful in
  1332. sequential-access files), although they will look very strange.
  1333.  
  1334. The strings are encrypted (or decrypted) in place.  This
  1335. provides a certain extra measure of security for encryption--
  1336. the original plaintext strings are not left floating around in
  1337. memory where someone might see them.
  1338.  
  1339. One function is as much a file manipulation routine as it is a
  1340. string function.  It allows you to compare a file name to a
  1341. file pattern (which may contain wildcards) to see if they
  1342. match.  Only bare filespecs are supported-- you may not use
  1343. drive or path specifications in the names.
  1344.  
  1345.    IF MatchFile%(Pattern$, Filename$) THEN PRINT Filename$
  1346.  
  1347.                             Strings                     page 29
  1348.  
  1349.  
  1350.  
  1351. The MatchFile function can be used in creating your own
  1352. DOS-style utilities: DIR, COPY, and so forth.  Besides the
  1353. usual "accept file if it matches" approach, it can also be used
  1354. to implement the opposite: "exclude file if it matches."  This
  1355. gives you more flexibility than DOS itself supplies.
  1356.  
  1357. The PowerBASIC compiler provides a very nice function called
  1358. Extract$.  This allows you to retrieve a substring running from
  1359. the left side of a main string to a specified character
  1360. delimiter.  Not bad, but it might be handy to be able to grab a
  1361. numbered substring from any part of a main string, and to be
  1362. able to use a substring delimiter.  For instance, you might
  1363. load a record from a database which contains an address, where
  1364. each line is delimited by a carriage return and linefeed.
  1365. Rather than mucking around with Extract$, which really wasn't
  1366. designed with that sort of thing in mind, you'd do better to
  1367. use the PBWiz function called DelimExtract$:
  1368.  
  1369.    SubSt$ = DelimExtract$(St$, Delimiter$, Index%)
  1370.  
  1371. The index starts at 1 with the first substring.  If you choose
  1372. the index of a substring which doesn't actually exist, a null
  1373. string will be returned.
  1374.  
  1375.                             Credits                     page 30
  1376.  
  1377.  
  1378.  
  1379. I'd like to thank Dave Navarro for letting me in on the world
  1380. of PowerBASIC. His assistance has been most valuable to me in
  1381. many respects.  Without him, this library would have taken much
  1382. longer to get off the ground or would perhaps not even exist.
  1383. Dave runs the excellent Bard's Lair BBS-- see my WHERE.BBS file
  1384. for more details.
  1385.  
  1386. I would also like to thank Spectra, publishers of PowerBASIC,
  1387. for sending me the evaluation copy of PowerBASIC which led to
  1388. my decision to write this library.
  1389.  
  1390.